import { RouteLocationNormalized } from "vue-router";
import { useUserStore } from "../store/user";
import { getConfig, magicCheckAuth } from "@ui/vue/api"

export function checkLogin(to?: RouteLocationNormalized): Promise<boolean> {
  const judge = !(to && to.meta && to.meta.requiresLogin) && useUserStore().getIsUser
  if (judge) {
    return magicCheckAuth().then((res) => !!res)
  } else
    getConfig()
  return Promise.resolve(false)
}